package com.zhuiYun.project.api.commodity.controller;
import com.alibaba.fastjson.JSONArray;
import com.zhuiYun.project.annotation.OptLog;
import com.zhuiYun.project.api.commodity.entity.Commodity;
import com.zhuiYun.project.api.commodity.model.CommodityModel;
import com.zhuiYun.project.api.commodity.service.CommodityService;
import com.zhuiYun.project.api.commodityType.entity.CommodityType;
import com.zhuiYun.project.common.controller.BaseController;
import com.zhuiYun.project.common.errorCode.CommonException;
import com.zhuiYun.project.common.response.CommonConstants;
import com.zhuiYun.project.common.response.CommonResult;
import com.zhuiYun.project.util.pageUtil.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
 * @ClassName CommodityController
 * @Description TODO
 * Author 高
 * @Date 2023/4/3 10:27
 * @Version 1.0
 **/
@RestController
@RequestMapping("/Commodity")
@Api(tags = "日志操作模块")
@Slf4j
public class CommodityController extends BaseController {
    @Autowired
    CommodityService commodityService;
    /**
     * 查询商品信息
     * @param CommodityModel
     * @return
     */
    @GetMapping("/getCommodityByPage")
    @ApiOperation(value = "商品信息管理的分页查询方法")
    @OptLog(modular = "商品信息管理", type = CommonConstants.SELECT, describe = "分页查询")
    public CommonResult getCommodityByPage(CommodityModel CommodityModel, PageRequest pageRequest) throws CommonException {
        log.info("商品信息管理");
        return commodityService.getCommodityByPage(CommodityModel,pageRequest);
    }
    /**
     * 查询未上架商品信息
     * @param CommodityModel
     * @return
     */
    @GetMapping("/getCommodityByPage1")
    @ApiOperation(value = "未上架商品信息管理的分页查询方法")
    @OptLog(modular = "未上架商品信息管理", type = CommonConstants.SELECT, describe = "分页查询")
    public CommonResult getCommodityByPage1(CommodityModel CommodityModel, PageRequest pageRequest) throws CommonException {
        log.info("未上架商品信息管理");
        return commodityService.getCommodityByPage1(CommodityModel,pageRequest);
    }
    /**
     * 商品回收站商品信息
     * @param CommodityModel
     * @return
     */
    @GetMapping("/getCommodityByPage2")
    @ApiOperation(value = "商品回收站管理的分页查询方法")
    @OptLog(modular = "商品回收站管理", type = CommonConstants.SELECT, describe = "分页查询")
    public CommonResult getCommodityByPage2(CommodityModel CommodityModel, PageRequest pageRequest) throws CommonException {
        log.info("商品回收站管理");
        return commodityService.getCommodityByPage2(CommodityModel,pageRequest);
    }
    /**
     * 添加商品信息
     * @param
     * @return
     */
    @PostMapping("/publishCommodityAdd")
    @ApiOperation(value = "商品管理的新增方法")
    @OptLog(modular = "商品管理", type = CommonConstants.ADD, describe = "新增商品")
    public CommonResult CommodityAdd(MultipartFile[] goodsImg, MultipartFile[] viewImg, CommodityModel publish) throws CommonException{
        int i = commodityService.CommodityAdd(goodsImg,viewImg, publish);
        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.error("添加失败");
        }
    }    /**
     * 添加未上架商品信息
     * @param
     * @return
     */
    @PostMapping("/publishCommodityAdd1")
    @ApiOperation(value = "商品管理未上架商品的新增方法")
    @OptLog(modular = "商品管理", type = CommonConstants.ADD, describe = "新增商品管理未上架商品")
    public CommonResult CommodityAdd1(MultipartFile[] goodsImg, MultipartFile[] viewImg, CommodityModel publish) throws CommonException{
        int i = commodityService.CommodityAdd1(goodsImg,viewImg, publish);
        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.error("添加失败");
        }
    }
    /**
     * 修改商品信息
     * @param
     * @return
     */
    @PostMapping("/publishCommodityUpdate")
    @ApiOperation(value = "商品管理的修改方法")
    @OptLog(modular = "商品修改", type = CommonConstants.UPDATE, describe = "修改商品")
    public CommonResult CommodityUpdate(MultipartFile[] goodsImg, MultipartFile[] viewImg, CommodityModel publish) throws CommonException{
        int i = commodityService.CommodityUpdate(goodsImg,viewImg, publish);
        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.error("修改失败");
        }
    }
    /**
     * 下架商品信息
     * @param id
     * @return
     */
    @DeleteMapping("/delCommodityById")
    @ApiOperation(value = "商品下架的方法")
    @OptLog(modular = "商品下架", type = CommonConstants.DELETE, describe = "下架商品")
    public CommonResult delCommodityById(Integer id) throws CommonException {
        log.info("删除用户信息");
        return commodityService.delCommodityById(id);
    }
    /**
     * 上架商品信息
     * @param id
     * @return
     */
    @DeleteMapping("/delCommodityById1")
    @ApiOperation(value = "商品上架的方法")
    @OptLog(modular = "商品上架", type = CommonConstants.DELETE, describe = "上架商品")
    public CommonResult delCommodityById1(Integer id) throws CommonException {
        log.info("上架用户信息");
        return commodityService.delCommodityById1(id);
    }
    /**
     * 删除未上架商品信息
     * @param id
     * @return
     */
    @DeleteMapping("/delCommodityById2")
    @ApiOperation(value = "删除未上架的方法")
    @OptLog(modular = "删除未上架", type = CommonConstants.DELETE, describe = "删除未上架")
    public CommonResult delCommodityById2(Integer id) throws CommonException {
        log.info("删除未上架信息");
        return commodityService.delCommodityById2(id);
    }
    /**
     * 回收信息
     * @param id
     * @return
     */
    @DeleteMapping("/delCommodityById3")
    @ApiOperation(value = "商品回收的方法")
    @OptLog(modular = "商品下架", type = CommonConstants.DELETE, describe = "回收商品")
    public CommonResult delCommodityById3(Integer id) throws CommonException {
        log.info("回收信息");
        return commodityService.delCommodityById3(id);
    }
    /**
     * 删除回收商品信息
     * @param id
     * @return
     */
    @DeleteMapping("/delCommodityById4")
    @ApiOperation(value = "删除回收商品的方法")
    @OptLog(modular = "删除回收商品", type = CommonConstants.DELETE, describe = "删除回收商品")
    public CommonResult delCommodityById4(Integer id) throws CommonException {
        log.info("删除回收商品信息");
        return commodityService.delCommodityById4(id);
    }
    /**
     * 类型下拉框
     * @param
     * @return
     */
    @GetMapping("/getTypeName")
    public CommonResult getTypeName(){
        List<CommodityType> getTypeName = commodityService.getCommodityType();
        return CommonResult.ok(getTypeName);
    }


    @GetMapping("commodityllist")
    CommonResult commodityllist(CommodityModel commodityModel){
        CommonResult commonResult = commodityService.commodityllist(commodityModel);
        log.info("diy查询用户信息");
        return commonResult;
    }


}
